import { FETCH_BING_PHOTOS_SUCCESS, FETCH_BING_PHOTOS_FAILURE } from './types'
import { call, put } from 'redux-saga/effects'
import { request } from '../../vender/request'

export function* fetchBingPhotos(action: IAction) {
  try {
    const photos = yield call(request.fetchBingPhotos, action.params)
    yield put({ type: FETCH_BING_PHOTOS_SUCCESS, payload: photos.data })
  } catch (err) {
    yield put({
      type: FETCH_BING_PHOTOS_FAILURE,
      payload: {
        message: '获取 Bing 图片失败'
      },
      error: true
    })
  }
}
